<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<script src="<%=request.getContextPath()%>/js/jquery.min.js"
		type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/validation.js"
		type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/common.js"
		type="text/javascript"></script>
<script>
	 var contextPath = "<%=request.getContextPath()%>";
	 var emailVerify,verificationVerify;
	 $(function(){
		 
		    emailVerify = new LiveValidation('email' , {onlyOnBlur: true});
			emailVerify.add(Validate.Email, { failureMessage: "请输入正确的电子邮箱地址"} );
			emailVerify.add(Validate.Presence, { failureMessage: "请输入正确的电子邮箱地址"}  );
			verificationVerify = new LiveValidation('verification', {onlyOnBlur: true});
			verificationVerify.add(Validate.Presence, { failureMessage: "请输入密码"} );
	});

	function submitApply(form) {
		
		var a = LiveValidation.massValidate( [ emailVerify, verificationVerify] );
		 var invalidSize = $('.LV_invalid_field').size();
		 if(invalidSize>0){
			 return;
		 }
		 
		var email = $('#email').val();
	 	var verification = $('#verification').val();
	 	
	 	$.ajax({ 
	          type: "POST", 
	          url: contextPath + "/applyResetPassword", 
	          data:"user.email="+email +  "&verification=" + verification, 
	          success: function(msg){ 
	 			msg = msg.replace("[","").replace("]","");
	 			var obj = $.parseJSON(msg);
	 			if(obj.applySuccess == 1) {
	 				$('#applyForm').hide();
	 				$('#info').text("确认邮件已发出,请查看邮件");
	 				$('#info').show();
		 		} else if(obj.emailError == 1) {
	 				$('#email').addClass("LV_invalid_field");
	 				$('#email').next().removeClass("LV_valid");
	 				$('#email').next().addClass("LV_invalid");
	 				$('#email').next().text("无此注册邮箱");
					
		 		} else if(obj.verifyError == 1) {
		 			$('#verification').addClass("LV_invalid_field");
	 				$('#verification').next().removeClass("LV_valid");
	 				$('#verification').next().addClass("LV_invalid");
	 				$('#verification').next().text("验证码错误");
	 				refreshCaptcha();
			 	}
		 		
	         } 
	     }); 
	}

</script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/validation.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/account.css" />
</head>
<body>
  <div class="wrapper">
  <div class="header-bar">
  <div class="header content clearfix">
  	<button onclick="window.location.href='<%=request.getContextPath()%>/viewRegister'" type="button" class="btn-info" style=" margin: 20px 20px 20px 20px;height: 32px; width:100px;font-size: 13px;float: right;">注册</button>
  </div>
  </div>
  <div class="main content clearfix">
  <div class="sign-in">
<div class="signin-box">
  <h2>找回密码</h2>
  <form  id="applyForm" action="<%=request.getContextPath()%>/login" method="post">
<div class="email-div">
  <label for="Email"><strong class="email-label">电子邮箱</strong></label>
  <input type="text" name="user.email" id="email" value="${user.email}">
</div>
<div class="verify_div">
	<label for="verification"><strong class="verify-label">验证码</strong></label>
	<img onclick="refreshCaptcha()" id="jcaptcha" src="jcaptcha.jpg" width="100" height="40"/> 
 	 <input type="text" name="verification" value="" id="verification"/>
</div>
  <button type="button" class="btn btn-danger" onclick="submitApply(this.form)">申请</button>
</form>
  <div>
	<span id="info" class="invalid_msg" style="text-align: center;display: none"></span>
  </div>
</div>
  </div>
  <div class="product-info ">
<div class="product-headers">
  <h1 class="redtext">帐户</h1>
</div>
<p>申请密码重置后，系统会发送确认邮件到邮箱。
</p><p>在确认成功后，密码会被重置并发送到您的邮箱。 </p>
  </div>
  </div>
  </div>
</body>
</html>